package com.ls.inittemplate.config;


import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * RabbitMQ初始化前配置
 *
 * <pre>
 * {@code
 *     @Resource
 *     private RabbitAdmin rabbitAdmin;
 *
 *     // 直接交换机
 *     @Resource
 *     private DirectExchange rabbitmqDemoDirectExchange;
 *
 *     @Resource
 *     private Queue rabbitmqDemoDirectQueue;
 *
 *     // 发布订阅交换机（分发交换机）
 *     @Resource
 *     private FanoutExchange fanoutExchange;
 *
 *     @Resource
 *     private Queue fanoutQueueA;
 *
 *     @Resource
 *     private Queue fanoutQueueB;
 *
 *     // 主题交换机
 *     @Resource
 *     private TopicExchange topicExchange;
 *
 *     @Resource
 *     private Queue topicQueueA;
 *
 *     @Resource
 *     private Queue topicQueueB;
 *
 *     @Resource
 *     private Queue topicQueueC;
 *
 *     @Override
 *     public void run(ApplicationArguments args) {
 *         // 应用初始化后执行声明操作
 *         // 声明直接交换机和队列
 *         rabbitAdmin.declareExchange(rabbitmqDemoDirectExchange);
 *         rabbitAdmin.declareQueue(rabbitmqDemoDirectQueue);
 *         // 声明发布订阅交换机和队列
 *         rabbitAdmin.declareExchange(fanoutExchange);
 *         rabbitAdmin.declareQueue(fanoutQueueA);
 *         rabbitAdmin.declareQueue(fanoutQueueB);
 *         // 声明主题交换机和队列
 *         rabbitAdmin.declareExchange(topicExchange);
 *         rabbitAdmin.declareQueue(topicQueueA);
 *         rabbitAdmin.declareQueue(topicQueueB);
 *         rabbitAdmin.declareQueue(topicQueueC);
 *         System.out.println("交换机和队列已在初始化时声明完成");
 *     }
 * }
 * </pre>
 */
@Component
public class RabbitMQInitializer implements ApplicationRunner {
    @Resource
    private RabbitAdmin rabbitAdmin;

    @Override
    public void run(ApplicationArguments args) throws Exception {

    }
}
